﻿package com {
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;

    public final class MapKey {

        public static const KEY_W:int = 87;
        public static const KEY_A:int = 65;
        public static const KEY_S:int = 83;
        public static const KEY_D:int = 68;
        public static const KEY_Space:int = 32;
        public static const KEY_RIGHT:int = 39;
        public static const KEY_LEFT:int = 37;
        public static const KEY_DOWN:int = 40;
        public static const KEY_UP:int = 38;
        public static const Event_Space:String = "Event_Space";

        private static var _MouseLeft:int = 0;
        private static var _MouseLeftTime:int = 0;
        private static var _keyArray:Array = [];
        private static var _ed:EventDispatcher = new EventDispatcher();

        public static function initKey(_arg1:Stage):void{
            _arg1.addEventListener(MouseEvent.MOUSE_UP, stageMouseUp);
            _arg1.addEventListener(MouseEvent.MOUSE_DOWN, stageMouseDown);
            reset();
        }
        public static function uninitKey(_arg1:Stage):void{
            _arg1.removeEventListener(MouseEvent.MOUSE_UP, stageMouseUp);
            _arg1.removeEventListener(MouseEvent.MOUSE_DOWN, stageMouseDown);
            reset();
        }
        public static function keyDownHandler(_arg1:KeyboardEvent):void{
            _keyArray[_arg1.keyCode] = true;
        }
        public static function keyUpHandler(_arg1:KeyboardEvent):void{
            _keyArray[_arg1.keyCode] = false;
            if (_arg1.keyCode == KEY_Space){
                _ed.dispatchEvent(new Event(Event_Space));
            };
        }
        public static function reset():void{
            if (_keyArray.length > 0){
                _keyArray = [];
            };
            _MouseLeft = 0;
        }
        public static function addEventListener(_arg1:String, _arg2:Function):void{
            _ed.addEventListener(_arg1, _arg2);
        }
        public static function removeEventListener(_arg1:String, _arg2:Function):void{
            _ed.removeEventListener(_arg1, _arg2);
        }
        private static function stageMouseUp(_arg1:Event):void{
            _MouseLeft = 0;
            _MouseLeftTime = getTimer();
        }
        private static function stageMouseDown(_arg1:Event):void{
            var _local2:DisplayObject = (_arg1.target as DisplayObject);
            while (_local2) {
//                if ((_local2 is IMap)){
//                    _MouseLeft = 1;
//                    _MouseLeftTime = getTimer();
//                    break;
//                };
                _local2 = _local2.parent;
            };
        }
        public static function get isKeyAorLeft():int{
            if (_keyArray[KEY_A] == true){
                return (1);
            };
            if (_keyArray[KEY_LEFT] == true){
                return (1);
            };
            return (0);
        }
        public static function get isKeyDorRIGHT():int{
            if (_keyArray[KEY_D] == true){
                return (1);
            };
            if (_keyArray[KEY_RIGHT] == true){
                return (1);
            };
            return (0);
        }
        public static function get isKeySorDOWN():int{
            if (_keyArray[KEY_S] == true){
                return (1);
            };
            if (_keyArray[KEY_DOWN] == true){
                return (1);
            };
            return (0);
        }
        public static function get isKeyWorUP():int{
            if (_keyArray[KEY_W] == true){
                return (1);
            };
            if (_keyArray[KEY_UP] == true){
                return (1);
            };
            return (0);
        }
        public static function get isMouseFollow():Boolean{
            return ((((_MouseLeft == 1)) && (((getTimer() - _MouseLeftTime) > 300))));
        }

    }
}//package com.assist.view.map 
